package xyx.ysfwpt.controller;

import io.swagger.annotations.*;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyx.ysfwpt.model.User;
import xyx.ysfwpt.service.TestService;

import java.util.List;

@RestController
@Api(tags = {"测试"},description = "swagger2测试")
public class TestController {

    @Autowired
    TestService testService;

    @ApiOperation(value = "查询",notes = "查询所有用户")
    @ApiResponses(value = { @ApiResponse(code = 200, message = "查询用户成功")})
    @GetMapping(value = "/select")
    public JSONObject select(){
        JSONObject jsonObject = new JSONObject();
        List<User> user = testService.selectUser();
        jsonObject.put("user",user);
        return jsonObject;
    }

    @ApiOperation(value = "查询",notes = "根据ID查询用户")
    @ApiResponses(value = { @ApiResponse(code = 200, message = "查询用户成功")})
    @GetMapping(value = "/selectByID")
    public JSONObject selectByID(@ApiParam(value = "用户id",required = true)@RequestParam(value = "id", required = true) int id){
        JSONObject jsonObject = new JSONObject();
        User user = testService.selectUserById(id);
        jsonObject.put("user",user);
        return jsonObject;
    }
}
